package com.elitel.frame.base.user;

import com.alibaba.fastjson.JSONObject;
import com.elitel.common.auth.service.SysUserService;
import com.elitel.common.core.domain.SysUserInfo;
import com.elitel.frame.base.service.SysWhitelistService;
import com.elitel.frame.main.entity.SysWhitelist;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author mulis
 */
@Service
public class SysUserServiceImpl extends SysUserService {
    @Resource
    private SysWhitelistService whitelistService;

    /**
     * 获取用户信息
     *
     * @param verifyFieldValue
     * @return
     */
    @Override
    public SysUserInfo getUserInfoFromRemote(String verifyFieldValue) {
        if (verifyFieldValue == null) return null;
        SysUserInfo userInfo;
        if (url == null) {
            SysWhitelist sysWhitelist = whitelistService.selectByVerifyField(verifyFieldValue);
            if (sysWhitelist == null) {
                return null;
            }
            userInfo = new SysUserInfo();
            userInfo.setAccount(sysWhitelist.getAccount());
            userInfo.setVerifyFiledVal(verifyFieldValue);
            userInfo.setExtendProp(JSONObject.parseObject(JSONObject.toJSONString(userInfo)));
            userInfo.setPermissions(sysWhitelist.getPermissions());
        } else {
            userInfo = super.getUserInfoFromRemote(verifyFieldValue);
        }
        return userInfo;
    }

}
